package com.pps.sdk.tester;

import com.pps.sdk.utils.ConfigHandler;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class MainActivity extends Activity implements OnClickListener,OnCheckedChangeListener{
	private UINavigation navigation;
	private Button query_data_btn;
	private Button query_payment_btn;
	private EditText gameIdText;
	private RadioButton radioBtn1;
	private RadioButton radioBtn2;
	private RadioGroup radiogroup;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_activity);
		
		navigation = (UINavigation) findViewById(R.id.uinavigation);
		navigation.setLeftBtn(false, null, 0, null);
		navigation.setRightBtn(false, null, 0, null);
		
		query_data_btn = (Button) findViewById(R.id.query_data_log);
		query_data_btn.setOnClickListener(this);
		query_payment_btn = (Button) findViewById(R.id.query_payment_log);
		query_payment_btn.setOnClickListener(this);
//		query_payment_btn.setVisibility(View.GONE);
		
		gameIdText = (EditText) findViewById(R.id.gameid);
		
		radiogroup = (RadioGroup) findViewById(R.id.statue_group);
		radiogroup.setOnCheckedChangeListener(this);
		radioBtn1 = (RadioButton) findViewById(R.id.statue_ok);
		radioBtn2 = (RadioButton) findViewById(R.id.statue_no);
		
		initView();
	}
	
	private void initView(){
		if(ConfigHandler.isTestPhone()){
			radioBtn1.setChecked(true);
		}else{
			radioBtn2.setChecked(true);
		}
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		if(arg0.getId() == query_data_btn.getId()){
			Intent intent = new Intent(this,DataListActivity.class);
			intent.putExtra("gamdId", gameIdText.getEditableText().toString());
			startActivity(intent);
			return ;
		}
		
		if(arg0.getId() == query_payment_btn.getId()){
			Intent intent = new Intent(this,PaymentListActivity.class);
			intent.putExtra("gamdId", gameIdText.getEditableText().toString());
			startActivity(intent);
			return ;
		}
	}

	@Override
	public void onCheckedChanged(RadioGroup arg0, int arg1) {
		// TODO Auto-generated method stub
		if(radioBtn1.getId() == arg1){
			ConfigHandler.setTestPhone(true);
			return ;
		}
		
		if(radioBtn2.getId() == arg1){
			ConfigHandler.setTestPhone(false);
			return ;
		}
	}
	
}
